home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_26199.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  27 lines

  1. -- card: 26199 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. Frequently pointers are used to structure variables.  A special operator '->' is used in place of the dot operator to access members of a structure pointed to by a pointer variable, to avoid cumbersome syntax.  It is important to remember to define a non-pointer variable as well in order to allocate space for the structure itself:
  11.  
  12.     struct personnel_rec  *person_ptr,
  13.                                              jack;
  14.     person_ptr = &jack;                   /*  if you forget this you may crash the program!  */
  15.     person_ptr->salary = 1.5e6;      /*  same as:  (*person_ptr).salary = 1.5e6  */
  16.  
  17. The same array-pointer relationship holds as that for the basic data types.
  18.  
  19.     struct personnel_rec  person[10];
  20.     (person+1)->salary = 1.5e6;      /*  ok since space is allocated in previous line  */
  21.  
  22. It is illegal to declare a member of a struct to be a variable of the same user-defined type.  For example, a personnel_rec variable may not be a member of the       personnel_rec type, for obvious reasons.  However, it is legal to declare a member to
  23.  
  24.  
  25. -- part contents for background part 7
  26. ----- text -----
  27. 68